home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1
/
Ian and Stuart's One (Australia).iso
/
Australasian Legends
/
Commercial
/
Rainbow Hill
/
MacDOS™ 2.0.0
/
batches
/
search.bat
< prev
next >
Wrap
DOS Batch File
|
1993-10-30
|
3KB
|
109 lines
@echo off
! search.bat Batch file to search files for a string.
! The search is case insensitive and only the first occurrence
! of each file is found.
! Only files of type TEXT are scanned and the maximum line length
! is approximately 100 characters.
! Note that search.bat leaves CONFIRM ON
!
! search name what [opt...]
!
! where:
! name = what is to be searched. It is either a folder name, or a file name
! (possibly wildcarded)
! what = the string to be found
! opt... = options as specified for DIR, one option per argument, up to 6
!
! Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
!
! initialisation
set search_file=TEMP8888
onerror ERR_LBL
! ensure that the first and second parameters are there
set doserr=13
if "%1 " == " " goto ERR_LBL
if "%2 " == " " goto ERR_LBL
! prepare a file with all filenames to be searched
dir %1 %3 %4 %5 %6 %7 %8 %9 /B/A-D/T=TEXT > %search_file%
! convert the string to uppercase so that the search is case insensitive
set search_string=%2
toupper search_string
! open the file containing the list of files to be searched
open %search_file% search_dirFileID
! scan the list of files
repeat DIR_LBL
! obtain a file name
onerror ENDDIR_LBL
read %search_dirFileID% search_fileName
! remove the double quotes which enclose the names
decr search_fileName
decr -search_fileName
! open the file
onerror ERR_LBL
open %search_fileName% search_fileID
echo "%search_fileName%"
! reset the line count
set search_lineNum=0
! read the file
:FILE_LBL
! read one line
onerror ENDFILE_LBL
read %search_fileID% search_line
incr search_lineNum
! search the line for the string
set search_upLine=%search_line%
toupper search_upLine
onerror FILE_LBL
sstr search_upLine %search_string%
! if we arrive here the string was found
echo %search_lineNum%: %search_line%
set doserr=0
goto ENDFILE_LBL
goto FILE_LBL
:ENDFILE_LBL
! the file was automatically closed when the EOF was reached
if %doserr% == 3 goto DIR_LBL
if not %doserr% == 0 goto ERR_LBL
onerror
close %search_fileID%
:DIR_LBL
:ENDDIR_LBL
if not %doserr% == 3 goto ERR_LBL
goto DONE_LBL
:ERR_LBL
show %doserr%
:DONE_LBL
! just in case...
onerror
close %search_fileID%
close %search_dirFileID%
confirm off
del %search_file%
confirm on
set search_string=
set search_dirFileID=
set search_fileName=
set search_fileID=
set search_lineNum=
set search_line=
set search_upLine=
set search_file=